<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="javax.portlet.*"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@page import ="rai.dto.*" %>
<%@page import ="rai.dao.*" %>
<%@page import = "java.util.*" %>
<script type="text/javascript">
	function getForm(namespace, name) {
		return document.forms[namespace + name];
	}
	function access_to_search_form(namespace, name){
		var frm = getForm(namespace , name);
		frm.txtAction.value = "access_to_search_form";
		frm.submit();
	}
	function edit_profile(namespace, name){
		var frm = getForm(namespace , name);
		frm.txtAction.value = "edit_profile";
		frm.submit();
	}
	function getbackresult(namespace, name){
		var frm = getForm(namespace , name);
		frm.txtAction.value = "get_back";
		frm.submit();
		}
	function back_to_login(namespace, name) {
		var frm = getForm(namespace, name);
		frm.txtAction.value = "back_to_login_form";
		frm.submit();
	}
	function access_to_edit_info_form(namespace, name) {
		var frm = getForm(namespace, name);
		frm.txtAction.value = "access_to_edit_info_form";
		frm.submit();
	}
	function add_new_tkn_prj_form(namespace, name) {
		var frm = getForm(namespace, name);
		frm.txtAction.value = "add_new_tkn_prj_form";
		frm.submit();
	}
	function access_to_edit_prj_form(namespace, name,PrjID) {
		var frm = getForm(namespace, name);
		
		frm.txtAction.value = "access_to_edit_prj_info_form";
		frm.PassingProjectID.value = PrjID;
		frm.submit();
		
	}
	function access_to_edit_exp_form(namespace, name,DepartID) {
		var frm = getForm(namespace, name);
		frm.txtAction.value = "access_to_edit_exp_form";
		frm.PassingDepartID.value = DepartID;
		frm.submit();
	}
	function access_to_edit_tkn_course(namespace,name,CourseID){
		var frm = getForm(namespace, name);
		frm.txtAction.value = "access_to_edit_tkn_course";
		frm.PassingCourseID.value = CourseID;
		frm.submit();
	}
	//delete action
	function delete_exp(namespace,name){
		var frm = getForm(namespace, name);
		frm.txtAction.value = "delete_emp_exp";
		frm.submit();
	}
	function delete_course(namespace,name){
		var frm = getForm(namespace, name);
		frm.txtAction.value = "delete_emp_course";
		frm.submit();
	}
	function delete_prj(namespace,name){
		var frm = getForm(namespace, name);
		frm.txtAction.value = "delete_emp_prj";
		frm.submit();
	}
	//add action
	function add_exp(namespace,name){
		var frm = getForm(namespace, name);
		frm.txtAction.value = "access_add_emp_exp";
		frm.submit();
	}
	function add_course(namespace,name){
		var frm = getForm(namespace, name);
		frm.txtAction.value = "access_add_emp_course";
		frm.submit();
	}
	function add_prj(namespace,name){
		var frm = getForm(namespace, name);
		frm.txtAction.value = "access_add_emp_prj";
		frm.submit();
	}
	//go to action
	function goto_course_info(namespace,name,courseID){
		var frm = getForm(namespace, name);
		frm.ViewCourseID.value = courseID;
		frm.txtAction.value = "goto_course_info";
		frm.submit();
	}
	function goto_prj_info(namespace,name,prjID){
		var frm = getForm(namespace, name);
		frm.ViewProjectID.value = prjID;
		frm.txtAction.value = "goto_project_info";
		frm.submit();
	}
	
</script>

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Personal Information Tracking System</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href='<%=request.getContextPath()+"css/style.css"%>' rel="stylesheet" type="text/css" media="screen" /></head>

<body>
<form name="<portlet:namespace/>empinfoForm" action="<portlet:actionURL/>" method="POST">
	<input type="hidden" name="txtAction" />
	<input type="hidden" name="PassingDepartID"/>
	<input type="hidden" name="PassingProjectID"/>
	<input type="hidden" name="PassingCourseID"/>
	<input type="hidden" name="ViewProjectID"/>
	<input type="hidden" name="ViewCourseID"/>
<table align="center">
	<tr class="title">
			<td>		
					<h1><font color="blue">Personal information tracking system</font></h1>
					<p>Exploit the value of data</p>
					<hr />
			</td>
	</tr>
	<%Integer myid=(Integer) session.getAttribute("ID");
	  String id=(String) session.getAttribute("PassingEmpID");
	  String name=(String) session.getAttribute("PassingEmpName");
	  String birthday=(String) session.getAttribute("PassingEmpBirthday");
	  String address=(String) session.getAttribute("PassingEmpAddress");
	  String phone=(String) session.getAttribute("PassingEmpPhone");
	  String email=(String) session.getAttribute("PassingEmpEmail");
	  String role = (String) session.getAttribute("role");
	  if ((id != null) && (!id.equals(""))) {
	      if (myid == Integer.parseInt(id)) {
	  	      	id = "";
	      }
	  }
	  %>
	  
	 <tr>
		<td colspan="2" align="left"> Welcome, <font color="orange"/><b>[${sessionScope.role}]${sessionScope.name}</b></font>
		| <a href="#">Home</a> 
		<%if(role.equals("PM")){ %>
			| <a href="#" onclick="access_to_search_form('<portlet:namespace/>','empinfoForm')">Search</a>
			<%if (!id.equals("")){%>
			| <a href="#" onclick="getbackresult('<portlet:namespace/>','empinfoForm')">Back To Result</a><%} %>
		<%} %>
		| <a href="#" onclick="edit_profile('<portlet:namespace/>','empinfoForm')">Edit Profile</a>
		| <a href="#" onclick="back_to_login('<portlet:namespace/>','empinfoForm')">Logout</a>
			
	   </td>
	</tr>
	<tr>			
		<td>
			<table border="1">
				<tr>
					<td><h2 class="title">Employee Information </h2></td>
				</tr>
				<tr>
					<td><em>Personal Information </em></td>
				</tr>
				<tr>
					<td>
						<table border="1" width="100%">
							<tr>								
								<td align="center" valign="middle">ID</td>
								<td align="center" valign="middle">Name</td>
								<td align="center" valign="middle">BirthDay</td>
								<td align="center" valign="middle">Address</td>
								<td align="center" valign="middle">Email</td>
								<td align="center" valign="middle">Phone</td>
								<%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
									<td align="center" valign="middle"><div align="center">Action</div></td>
								<%} %>										
							</tr>
							<%
							if(id.equals("")){%>
							<tr>
							  <td align="center">${sessionScope.ID}</td>
							  <td align="center">${sessionScope.Name}</td>
							  <td align="center" valign="middle">${sessionScope.birthday}</td>
  							  <td align="center">${sessionScope.address}</td>
							  <td align="center">${sessionScope.email}</td>
							  <td align="center">${sessionScope.phone}</td>
							  <%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
							  	<td align="center" valign="middle"><input type="button" name="Button" value="Edit" onclick="access_to_edit_info_form('<portlet:namespace/>','empinfoForm')"/></td>
							  <%} %>
						  </tr>
						  <%}else{%>
						  		<tr>
							  <td align="center"><%=id%></td>
							  <td align="center"><%=name %></td>
							  <td align="center" valign="middle"><%=birthday %></td>
  							  <td align="center"><%=address %></td>
							  <td align="center"><%=email %></td>
							  <td align="center"><%=phone %></td>
							  <%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
							  	<td align="center" valign="middle"><input type="button" name="Button" value="Edit" onclick="access_to_edit_info_form('<portlet:namespace/>','empinfoForm')"/></td>
							  <%} %>
						  </tr>	
						  <%} %>			  
					  </table>
					</td>
				</tr>
				
				<tr>
					<td><em>Experience</em></td>
				</tr>
				<tr>
					<td>
						<table border="1" width="100%">
							<tr>
								<td align="center" valign="middle">&nbsp;Check&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Company&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Address&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Phone&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Department&nbsp;</td>
								<td align="center" valign="middle">&nbsp;StartDate&nbsp;</td>
								<td align="center" valign="middle">&nbsp;EndDate&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Role&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Short Description&nbsp;</td>
								<%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
									<td align="center" valign="middle"><div align="center">&nbsp;Action&nbsp;</div></td>
								<%} %>										
							</tr>
							<%EmployeeInfoDAO dao= new EmployeeInfoDAO();%>
							<%List<ExperienceDTO> List_exp = new ArrayList<ExperienceDTO>();
							  if(id.equals("")){
							  	List_exp = dao.getExperience(myid);
							  }else{
								List_exp = dao.getExperience(Integer.parseInt(id));  
							  }
							for (int i = 0; i < List_exp.size(); i++){
								ExperienceDTO exp = new ExperienceDTO();
								exp = List_exp.get(i); %>	
								<tr>
								  <td align="center"><input type="checkbox" name="chkExp" value='<%=exp.getDepartID() %>'></td>
								  <td align="center"><%=exp.getCompName()%></td>
								  <td align="center"><%=exp.getCompAddress() %></td>
								  <td align="center"><%=exp.getCompPhone() %></td>
								  <td align="center"><%=exp.getDepartName() %></td>
								  <td align="center"><%=exp.getStartDate() %></td>
								  <td align="center"><%=exp.getEndDate() %></td>
								  <td align="center"><%=exp.getRole() %></td>
								  <td align="center"><%=exp.getDescription() %></td>
								  <%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
								  	<td align="center" valign="middle"><a href="#" onclick="access_to_edit_exp_form('<portlet:namespace/>','empinfoForm','<%=exp.getDepartID()%>')">Edit</a></td>
								  <%} %>							
								</tr>
							 <%} %>
						  <tr>
						   	<td colspan="10" align="left" valign="middle">1 <a href="#">2</a> <a href="#">3</a> ...
						  <%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
							<input name="" type="button" value="Add" onclick="add_exp('<portlet:namespace/>','empinfoForm')"/>
					  	    <input name="" type="button" value="Delete" onclick="delete_exp('<portlet:namespace/>','empinfoForm')"/>
					  	  <%} %>
					  	  </td>
						  </tr>
					  </table>
					</td>
				</tr>
					
				<tr>
					<td><em>Taken Course(s)</em></td>
				</tr>
				<tr>
					<td>
						<table border="1" width="100%">
							<tr align="center" valign="middle">
								<td rowspan="2">&nbsp;Check&nbsp;</td>
								<td rowspan="2">&nbsp;Name&nbsp;</td>
								<td rowspan="2">&nbsp;Department/Institute Issued&nbsp;</td>
								<td rowspan="2">&nbsp;Period (day)&nbsp;</td>
								<td rowspan="2">&nbsp;Description&nbsp;</td>
								<td colspan="3">&nbsp;Technology&nbsp;</td>
								<td rowspan="2">&nbsp;Grade&nbsp;</td>
								<td rowspan="2">&nbsp;Date issued&nbsp;</td>
								<%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>					
									<td rowspan="2">&nbsp;Action&nbsp;</td>
								<%} %>										
							</tr>
							<tr align="center" valign="middle">
							  <td>Language</td>
						      <td>Framework/Technology</td>
						      <td>DBMS</td>
						  </tr>
						  <%	dao= new EmployeeInfoDAO();
								
								List<TakenCourseDTO> lstCourse = new ArrayList<TakenCourseDTO>();
								if (!id.equals("")){
									lstCourse=dao.getCourse(Integer.parseInt(id));
								}else{
									lstCourse=dao.getCourse(myid);
								}
								for (int i = 0; i < lstCourse.size(); i++){
								TakenCourseDTO exp = new TakenCourseDTO();
								exp = lstCourse.get(i); %>
						  <tr>
								<td align="center"><label>									
										<input type="checkbox" name="chkCourse" value="'<%=exp.getId() %>'" />
									</label>								</td>
							  	<td align="left" valign="middle"><%if(role.equals("PM")){ %><a href="#" onclick="goto_course_info('<portlet:namespace/>','empinfoForm','<%=exp.getId() %>')"><%=exp.getSname() %></a><%}else{%> <%=exp.getSname()%> <%} %> </td>
							  	<td align="left" valign="middle"><%=exp.getDept() %></td>
							  	<td align="left" valign="middle"><%=exp.getPeriod() %></td>
							  	<td align="left" valign="middle"><%=exp.getDes() %></td>
								<td align="left" valign="middle"><%=exp.getLang() %></td>
								<td align="left" valign="middle"><%=exp.getFrw() %></td>
								<td align="center" valign="middle"><%=exp.getDatabase() %></td>
							  	<td align="center" valign="middle"><%=exp.getGrade() %></td>
							  	<td align="left" valign="middle"><%=exp.getDate() %></td>
								<%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
							  		<td align="center" valign="middle" onclick="access_to_edit_tkn_course('<portlet:namespace/>','empinfoForm','<%=exp.getId() %>')"><a href="#">Edit</a></td>
							  	<%} %>
						  	</tr>
							<%} %>
						  	<tr>
							  	<td colspan="11">1 <a href="#">2</a> <a href="#">3</a> ...
								<%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
							<input name="" type="button" value="Add" onclick="add_course('<portlet:namespace/>','empinfoForm')"/>
					  	    <input name="" type="button" value="Delete" onclick="delete_course('<portlet:namespace/>','empinfoForm')"/>
					  	  <%} %>
					  	  </td>
					  	  </tr>
						</table>
					</td>
				</tr>
					
				<tr>
					<td><p><em>Taken Project(s)</em></p></td>
				</tr>
				<tr>
					<td>
						<table border="1" width="100%">
							<tr align="center" valign="middle">
								<td><div align="center">&nbsp;Check&nbsp;</div></td>
								<td><div align="center">&nbsp;Project Name</div></td>
								<td><div align="center">&nbsp;Department&nbsp;</div></td>
								<td><div align="center">&nbsp;Start Date&nbsp;</div></td>							
								<td><div align="center">&nbsp;End Date&nbsp;</div></td>
								<td><div align="center">&nbsp;Role&nbsp;</div></td>
								<td><div align="center">&nbsp;Languages&nbsp;</div></td>
								<td><div align="center">&nbsp;Framework/Technology&nbsp;</div></td>
								<td><div align="center">&nbsp;Database&nbsp;</div></td>
								<td><div align="center">&nbsp;More Decriptions&nbsp;</div></td>
								<%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
									<td><div align="center">&nbsp;Action&nbsp;</div></td>
								<%} %>										
							</tr>
							<%	
								
								List<ProjectEmpInfoDTO> lstPrj = new ArrayList<ProjectEmpInfoDTO>();
								if (!id.equals("")){
									lstPrj=dao.getProject(Integer.parseInt(id));
								}else{
									lstPrj=dao.getProject(myid);
								}
								for (int i = 0; i < lstPrj.size(); i++){
									ProjectEmpInfoDTO exp = new ProjectEmpInfoDTO();
									exp = lstPrj.get(i); %>
							<tr>
							
							  <td><label>
									<input type="checkbox" name="chkPrj" value="<%=exp.getId() %>" />
								</label></td>
							  <td align="left" valign="middle"><%if(role.equals("PM")){ %><a href="#" onclick="goto_prj_info('<portlet:namespace/>','empinfoForm','<%=exp.getId() %>')"><%=exp.getSname() %></a><%}else{%> <%=exp.getSname() %> <%} %> </td>
							  <td align="left" valign="middle"><%=exp.getDept() %> </td>
							  <td align="left" valign="middle"><%=exp.getStart() %></td>  
							  <td align="left" valign="middle"><%=exp.getEnd() %></td>
							  <td align="left" valign="middle"><%=exp.getRole() %></td>
							  <td align="left" valign="middle"><%=exp.getLang() %></td>
							  <td align="left" valign="middle"><%=exp.getFrw() %></td>
							  <td align="center" valign="middle"><%=exp.getDatabase() %></td>
							  <td align="left" valign="middle"><%=exp.getDes() %></td>
							  <%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
							  	<td align="center" valign="middle"><a href="#" onclick="access_to_edit_prj_form('<portlet:namespace/>','empinfoForm','<%=exp.getId()%>')">Edit</a></td>
							  <%} %>
						  </tr>
							<%} %>
							
						  <tr>
						  	  <td colspan="11">1 <a href="#">2</a> <a href="#">3</a> ...
						  	 <%if(role.equals("Emp")||(role.equals("PM")&&id.equals(""))){ %>
							<input name="" type="button" value="Add" onclick="add_prj('<portlet:namespace/>','empinfoForm')"/>
					  	    <input name="" type="button" value="Delete" onclick="delete_prj('<portlet:namespace/>','empinfoForm')"/>
					  	  <%} %>
					  	  </td>
					  	  </tr>
					  </table>
					</td>
				</tr>
			</table>			
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<div style="clear: both;">&nbsp;</div>

			<div id="footer"><p>Development by HCMUT-Group3.</p>
			</div>
		</td>
	</tr>
</table>
</form>
</body>